package com.entor.service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.entor.dao.RoleDaoI;
import com.entor.model.Menu;
import com.entor.model.Msg;
import com.entor.model.Role;
import com.entor.model.RoleMenu;
import com.entor.util.MenuUtil;
import com.sun.org.apache.bcel.internal.generic.AALOAD;
@Service
public class RoleService implements BaseServiceI<Role>{

	@Autowired
	private RoleDaoI rdi;
	
	public List<Role> find(Role t) {
		List<Role> list = rdi.find(t);
		return list;
	}
	
	public Msg grant(String rid,String mids){
		Msg m = new Msg("授权失败",false);
		String ids[] = mids.split(",");
		List<String> list = new ArrayList<String>();
		list = Arrays.asList(ids);
		rdi.removeRid(rid);
		int i = rdi.grant(rid,list);
		if(i>0){
			m = new Msg("成功授权!", true);
		}
		return m;
	}
	
	public String findMenuByRid(Integer rid){
		List<Menu> list = rdi.findMenuByRid(rid);
		String menuStr = MenuUtil.createMenu(list);
		return menuStr;
	}
	
	public List<RoleMenu> findRoleMenu(RoleMenu r){
		return rdi.findRoleMenu(r);
	}

	public Role get(Role t) {
		return null;
	}

	public Msg insert(Role t) {
		return null;
	}

	public Msg batchInsert(String objs) {
		// TODO Auto-generated method stub
		return null;
	}

	public Msg edit(Role t) {
		// TODO Auto-generated method stub
		return null;
	}

	public Msg remove(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	public Msg batchRemove(String ids) {
		// TODO Auto-generated method stub
		return null;
	}

}
